/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package html;

import general.OutputProvider;
import java.io.Writer;

/**
 *
 * @author Alejandro
 */
public class XHtmlFormatter extends OutputProvider {

    public XHtmlFormatter(Writer out) {
        super(out);
    }

    public void startHtml() {
        echo("<html>");
    }

    public void endHtml() {
        echo("</html>");
    }

    public void startHead() {
        echo("<head>");
    }

    public void endHead() {
        echo("</head>");
    }

    public void startTitle() {
        echo("<title>");
    }

    public void endTitle() {
        echo("</title>");
    }

    public void writeTitle(String content) {
        startTitle();
        echo(content);
        endTitle();
    }

    public void writeMeta(String httpEquiv, String content) {
        echo("<meta http-equiv=\"" + httpEquiv + "\" content=\"" + content + "\" />");
    }

    public void writeLink(String rel, String type, String href) {
        echo("<link rel=\"" + rel + "\" type=\"" + type + "\" href=\"" + href + "\" />");
    }

    public void startBody() {
        echo("<body>");
    }

    public void endBody() {
        echo("</body>");
    }

    public void startH1() {
        echo("<h1>");
    }

    public void endH1() {
        echo("</h1>");
    }

    public void startH2() {
        echo("<h2>");
    }
    
    public void endH2() {
        echo("</h2>");
    }
    
    public void writeH1(String content) {
        startH1();
        echo(content);
        endH1();
    }

    public void writeH2(String content) {
        startH2();
        echo(content);
        endH2();
    }
    
    public void startTable() {
        echo("<table>");
    }
    
    public void endTable() {
        echo("</table>");
    }
    
    public void startTr() {
        echo("<tr>");
    }
    
    public void endTr() {
        echo("</tr>");
    }
    
    public void startTd() {
        echo("<td>");
    }
    
    public void endTd() {
        echo("</td>");
    }
    
    public void startForm(String name, String action, String method) {
        StringBuilder builder = new StringBuilder("<form");
        if (!name.isEmpty()) {
            builder.append(" name=\"");
            builder.append(name);
            builder.append("\"");
        }
        if (!action.isEmpty()) {
            builder.append(" action=\"");
            builder.append(action);
            builder.append("\"");
        }
        if (!method.isEmpty()) {
            builder.append(" method=\"");
            builder.append(method);
            builder.append("\"");
        }
        builder.append(">");
        echo(builder.toString());
    }

    public void startForm(String action, String method) {
        startForm("", action, method);
    }

    public void endForm() {
        echo("</form>");
    }

    public void writeInput(InputType type, String name, String id, String styleClass, String value) {
        echo("<input type=\"" + type.name() + "\" name=\"" + name + "\" id=\"" + id + "\" class=\"" + styleClass + "\" value=\"" + value + "\" />");
    }

    public void startDiv(String id, String styleClass) {
        StringBuilder builder = new StringBuilder("<div");
        if (!id.isEmpty()) {
            builder.append(" id=\"");
            builder.append(id);
            builder.append("\"");
        }
        if (!styleClass.isEmpty()) {
            builder.append(" class=\"");
            builder.append(styleClass);
            builder.append("\"");
        }
        builder.append(">");
        echo(builder.toString());
    }

    public void startDiv(String id) {
        startDiv(id, "");
    }

    public void startDiv() {
        startDiv("", "");
    }

    public void endDiv() {
        echo("</div>");
    }

    public void startP(String id, String styleClass) {
        StringBuilder builder = new StringBuilder("<p");
        if (!id.isEmpty()) {
            builder.append(" id=\"");
            builder.append(id);
            builder.append("\"");
        }
        if (!styleClass.isEmpty()) {
            builder.append(" class=\"");
            builder.append(styleClass);
            builder.append("\"");
        }
        builder.append(">");
        echo(builder.toString());
    }

    public void endP() {
        echo("</p>");
    }

    public void writeP(String id, String styleClass, String content) {
        startP(id, styleClass);
        echo(content);
        endP();
    }

    public void writeP(String styleClass, String content) {
        writeP("", styleClass, content);
    }
}
